package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.ZoneTag;
import com.ruoyi.swla2.service.IZoneTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分区参数标签页Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/region/zoneTag")
public class ZoneTagController extends BaseController {
    @Autowired
    private IZoneTagService zoneTagService;

    /**
     * 查询分区参数标签页列表
     */
    @PreAuthorize("@ss.hasPermi('region:zone:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZoneTag zoneTag) {
        startPage();
        List<ZoneTag> list = zoneTagService.selectZoneTagList(zoneTag);
        return getDataTable(list);
    }

    /**
     * 导出分区参数标签页列表
     */
    @PreAuthorize("@ss.hasPermi('region:zone:export')")
    @Log(title = "分区参数标签页", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZoneTag zoneTag) {
        List<ZoneTag> list = zoneTagService.selectZoneTagList(zoneTag);
        ExcelUtil<ZoneTag> util = new ExcelUtil<ZoneTag>(ZoneTag.class);
        util.exportExcel(response, list, "分区参数标签页数据");
    }

    /**
     * 获取分区参数标签页详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:zone:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(zoneTagService.selectZoneTagByID(ID));
    }

    @PreAuthorize("@ss.hasPermi('region:zone:query')")
    @GetMapping(value = "/getZoneTagByAreaId")
    public AjaxResult getZoneTagByAreaId(@RequestParam("areaId") String areaId) {
        return success(zoneTagService.getZoneTagByAreaId(areaId));
    }

    /**
     * 新增分区参数标签页
     */
    @PreAuthorize("@ss.hasPermi('region:zone:add')")
    @Log(title = "分区参数标签页", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZoneTag zoneTag) {
        zoneTag.setTenantId(this.getTenantId());
        return toAjax(zoneTagService.insertZoneTag(zoneTag));
    }

    /**
     * 修改分区参数标签页
     */
    @PreAuthorize("@ss.hasPermi('region:zone:edit')")
    @Log(title = "分区参数标签页", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZoneTag zoneTag) {
        return toAjax(zoneTagService.updateZoneTag(zoneTag));
    }

    /**
     * 删除分区参数标签页
     */
    @PreAuthorize("@ss.hasPermi('region:zone:remove')")
    @Log(title = "分区参数标签页", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(zoneTagService.deleteZoneTagByIDs(IDs));
    }
}
